package com.nt.mes_leader.model.db;

import android.content.Context;

import com.nt.mes_leader.utils.LogUtils;

import java.util.Collection;
import java.util.List;

/**
 * Created by netuo020 on 2017/9/20.
 */
public class DbModelImpl implements IDataModel {

    private static final String TAG = "DbModelImpl";

    private Context mContext;
    private Class mClass;
    protected LiteOrmManager mOrmManager;

    public <T> DbModelImpl(Context context, Class<T> tCls){
        this.mContext = context;
        this.mClass = tCls;
        mOrmManager = LiteOrmManager.getInstance(mContext);
        LogUtils.i(TAG, "DataModelImpl " + mClass.getName());
    }

    @Override
    public long save(Object o) {
        long id = mOrmManager.save(o);
        return id;
    }

    @Override
    public <T> int save(List<T> collection) {
        int id = mOrmManager.save(collection);
        return id;
    }

    @Override
    public int delete() {
        int id = mOrmManager.delete(mClass);
        return id;
    }

    @Override
    public void deleteAll(Class cls) {
        mOrmManager.delete(cls);
    }

    @Override
    public int deleteByObject(Object object) {
        int id = mOrmManager.delete(object);
        return id;
    }

    @Override
    public <T> int delete(Collection<T> var) {
        return mOrmManager.deleteByCollection(var);
    }

    @Override
    public int modify(Object o) {
        int id = mOrmManager.modify(o);
        return id;
    }

    @Override
    public <T> List<T> queryAll() {
        return mOrmManager.queryAll(mClass);
    }

    @Override
    public <T> T queryById(long id) {
        return (T) mOrmManager.queryById(id, mClass);
    }

    @Override
    public <T> List<T> queryOrderby(String orderby) {
        return mOrmManager.queryOrderby(mClass, orderby);
    }
}
